home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / comm / odys200a.zip / ODY200SH.LZH / ODYHOST.HSC < prev    next >
Text File  |  1993-04-26  |  12KB  |  452 lines

  1.  
  2. SCRIPT OdyHost;
  3.  
  4. (************************************************************************)
  5. (*                                                                      *)
  6. (*                     Odyssey Host Mode Script                         *)
  7. (*                Copyright (c) Don Milne, July 1990                    *)
  8. (*                                                                      *)
  9. (************************************************************************)
  10.  
  11. VAR DefaultBaudRate:Number;
  12.     GotLeaveCmd,PrivUser,LostCarrier:Flag;
  13.     CurrDir,OrigDir:String;
  14.     FileOK,GotChar,Carrier,AlreadyConnected,Busy:Flag;
  15.     OldCrMode:Number;
  16.  
  17. (* Host mode info, configured in Odyssey by user *)
  18. VAR NormPass,PrivPass,Welcome,HostDir:String;
  19.     MNPwanted:Flag;
  20.  
  21. (*.........................................*)
  22.  
  23. FUNC CarrierLost():Flag;
  24.  
  25. VAR tempcarrier:Flag;
  26.  
  27. BEGIN
  28.      IF LostCarrier THEN RETURN(TRUE) END;
  29.      tempcarrier := OnLine();
  30.      IF (Carrier<>tempcarrier) AND (NOT tempcarrier) THEN
  31.          Delay(1);
  32.          IF NOT OnLine() THEN
  33.              LostCarrier:=TRUE;
  34.              Carrier := FALSE;
  35.              AlreadyConnected := FALSE;
  36.              RETURN TRUE
  37.          END;
  38.      END;
  39.      RETURN FALSE;
  40. END;
  41.  
  42. (*.........................................*)
  43.  
  44. PROC SendString(s:String);
  45. BEGIN
  46.      Write(s); Transmit(s);
  47. END;
  48.  
  49. (*.........................................*)
  50.  
  51. FUNC GetString(VAR s:String; Timout:Number):Flag;
  52. BEGIN
  53.      IF Receive(s,Timout) THEN
  54.          Write(s+"|");
  55.          RETURN TRUE;
  56.      END;
  57.      RETURN FALSE;
  58. END;
  59.  
  60. (*.........................................*)
  61.  
  62. FUNC LeaveHostMode():Flag;
  63. BEGIN
  64.      IF NOT GotLeaveCmd THEN
  65.          WHILE KeyPressed() DO (* leave host mode? *)
  66.              IF RdKey()=27 THEN
  67.                  GotLeaveCmd := TRUE;
  68.              END;
  69.          END;
  70.      END;
  71.      RETURN GotLeaveCmd;
  72. END;
  73.  
  74. (*.........................................*)
  75.  
  76. FUNC GetPassWord():Flag;
  77.  
  78. VAR Attempts:Number;
  79.     GotPassword,Failure:Flag;
  80.     Password:String[20];
  81.  
  82. BEGIN
  83.      PrivUser := FALSE;
  84.      GotPassword := FALSE;
  85.      Failure := FALSE;
  86.      Attempts := 0;
  87.      REPEAT
  88.            SendString("|Enter Password: ");
  89.            Receive(Password,10,NoEcho);
  90.            IF Password = PrivPass THEN
  91.                PrivUser := TRUE;
  92.                GotPassword := TRUE
  93.              ELSIF Password = NormPass THEN
  94.                GotPassword := TRUE
  95.              ELSE
  96.                SendString("Incorrect ("+Password+")"); INC(Attempts);
  97.                Failure := (Attempts>=3);
  98.                IF Failure THEN
  99.                    SendString("||Wrong too often.. Byeee|");
  100.                    HangUp();
  101.                END;
  102.            END
  103.      UNTIL GotPassword OR Failure;
  104.      RETURN GotPassword;
  105. END;
  106.  
  107. (*.........................................*)
  108.  
  109. PROC ChangeDirectory();
  110.  
  111. VAR Temp:String;
  112.  
  113. BEGIN
  114.      SendString("|Directory? ");
  115.      IF GetString(Temp,30) THEN
  116.          IF Temp="" THEN RETURN END;
  117.          IF ChDir(Temp) THEN
  118.              CurrDir := Temp
  119.            ELSE
  120.              SendString("No such directory");
  121.              ChDir(CurrDir);
  122.          END;
  123.      END;
  124. END;
  125.  
  126. (*.........................................*)
  127.  
  128. PROC DirectoryListing();
  129.  
  130. VAR Lines,Count,f_attr:Number;
  131.     GotFile:Flag;
  132.     Temp:String;
  133.     Name:String[20];
  134.  
  135. BEGIN
  136.      SendString("Dir Mask? ");
  137.      IF NOT GetString(Temp,30) THEN RETURN END;
  138.      SendString('|');
  139.      IF Temp="" THEN Temp:="*.*" END;
  140.      GotFile := FFirst(Temp,0,Name,f_attr);
  141.      IF GotFile THEN
  142.          Count:=0; Lines:=0;
  143.          WHILE (GotFile) AND (NOT CarrierLost()) DO
  144.              Temp := Name;
  145.              Temp := SubStr(Temp+"              ",0,14);
  146.              SendString(Temp);
  147.              GotFile := FNext(Name,f_attr);
  148.              INC(Count);
  149.              IF Count % 5 = 0 THEN
  150.                  INC(Lines); SendString('|');
  151.                  IF Lines=20 THEN
  152.                      SendString("||More...");
  153.                      GetString(temp,30);
  154.                      IF CarrierLost() THEN RETURN END;
  155.                      SendString('||');
  156.                  END;
  157.              END;
  158.          END;
  159.        ELSE
  160.          SendString("No matching files.|");
  161.      END;
  162.      SendString('||');
  163. END;
  164.  
  165. (*................................................*)
  166.  
  167. FUNC GetFilename(VAR Filename:String; MustExist:Flag):Flag;
  168. BEGIN
  169.      SendString("|Filename? ");
  170.      IF NOT GetString(Filename,30) THEN
  171.          SendString('|');
  172.        ELSE
  173.          IF (Length(Filename)>12) OR (Pos(":",Filename)>=0) OR (Pos("\",Filename)>=0) THEN
  174.              (* for security reasons, path and drive names are not allowed *)
  175.              SendString("|Bad File name|");
  176.              RETURN FALSE;
  177.          END;
  178.          IF IsFile(Filename) THEN
  179.              IF MustExist THEN
  180.                  RETURN TRUE
  181.                ELSE
  182.                  SendString("|Filename used already - pick another!|");
  183.              END;
  184.            ELSIF MustExist THEN
  185.              SendString("|File not found.|");
  186.            ELSE
  187.              RETURN TRUE
  188.          END;
  189.      END;
  190.      RETURN FALSE;
  191. END;
  192.  
  193. (*................................................*)
  194.  
  195. FUNC GetFTMethod(AsciiOK:Flag):Number;
  196.  
  197. VAR c:String[2];
  198.     x:Number;
  199.  
  200. BEGIN
  201.      SendString("Choose method=>|");
  202.      IF AsciiOK THEN SendString("A(scii|") END;
  203.      SendString("X(modem|W(xmodem|Y(modem|B(atch Ymodem|K(ermit|Z(modem|?");
  204.      REPEAT
  205.            IF NOT GetString(c,30) THEN
  206.                RETURN -1;
  207.              ELSIF c<>"" THEN
  208.                x:=Pos(ToUpper(c),"AXYBWKZ");
  209.              ELSIF CarrierLost() THEN
  210.                RETURN -1;
  211.            END;
  212.      UNTIL ((x=0) AND (AsciiOK)) OR ((x>=1) AND (x<=6));
  213.      RETURN x;
  214. END;
  215.  
  216. (*................................................*)
  217.  
  218. PROC SayProtocol(prot:Number; AddDelay:Flag);
  219. BEGIN
  220.      CASE prot OF
  221.           0:SendString("ASCII");
  222.        |  1:SendString("Xmodem");
  223.        |  2:SendString("Ymodem");
  224.        |  3:SendString("Ymodem Batch");
  225.        |  4:SendString("WXmodem");
  226.        |  5:SendString("Kermit");
  227.        |  6:SendString("Zmodem");
  228.      END;
  229.      SendString(" protocol.|");
  230.      IF AddDelay THEN Delay(5) END;
  231. END;
  232.  
  233. (*................................................*)
  234.  
  235. PROC SayResult();
  236. BEGIN
  237.      SendString("|File Transfer ");
  238.      IF FileOK THEN
  239.          SendString("Complete.|")
  240.        ELSE
  241.          SendString("Failed.|")
  242.      END;
  243. END;
  244.  
  245. (*................................................*)
  246.  
  247. FUNC TransferFile(down:Flag; protocol:Number; FileSpec:String):Flag;
  248. BEGIN
  249.      IF down THEN
  250.          RETURN Download(protocol,FileSpec,ResumeTransfer);
  251.        ELSE
  252.          RETURN Upload(Protocol,FileSpec);
  253.      END;
  254. END;
  255.  
  256. (*................................................*)
  257.  
  258. PROC GetFileFromUser();
  259.  
  260. VAR x:Number;
  261.     Filename:String;
  262.  
  263. BEGIN
  264.      x := GetFTMethod(FALSE);
  265.      IF x<0 THEN RETURN END;
  266.      IF (x=XMODEM) OR (x=WXMODEM) OR (x=YMODEM) THEN
  267.          IF NOT GetFilename(Filename,FALSE) THEN RETURN END;
  268.      END;
  269.      SendString("|Ready to receive file using ");
  270.      SayProtocol(x,FALSE);
  271.      FileOK := TransferFile(TRUE,x,Filename);
  272.      SayResult();
  273. END;
  274.  
  275. (*................................................*)
  276.  
  277. PROC SendFileToUser();
  278.  
  279. VAR x:Number;
  280.     f:File;
  281.     blocks,bytes:String[10];
  282.     Filename:String;
  283.  
  284. BEGIN
  285.      x := GetFTMethod(TRUE);
  286.      IF x<0 THEN RETURN END;
  287.      IF NOT GetFilename(Filename,TRUE) THEN RETURN END;
  288.      FOpen(f,Filename);
  289.      FileSize(f,bytes,blocks);
  290.      FClose(f);
  291.      SendString("|File: "+Filename+"|  "+bytes+" bytes, ("+blocks+" Xmodem blocks).|");
  292.      SendString("About to send file using ");
  293.      SayProtocol(x,TRUE);
  294.      Filename := FQualify(Filename);
  295.      FileOK := TransferFile(FALSE,x,Filename);
  296.      SayResult();
  297. END;
  298.  
  299. (*................................................*)
  300.  
  301. PROC GetMenu();
  302.  
  303. VAR c:String[2];
  304.     x:Number;
  305.  
  306. BEGIN
  307.      REPEAT
  308.            IF CarrierLost() OR LeaveHostMode() THEN RETURN END;
  309.      UNTIL GetStr